<script type="text/javascript">
$(function () {
	$('.files_item').draggable({
		cursor: 'pointer',
		helper: 'clone',
		opacity: 0.3,
		revert: 'invalid'
	});
	
	$('.simple_tree_item_off').droppable({
		hoverClass: 'simple_tree_item_on',
		accept: '.files_item',
		tolerance: 'pointer',
		drop: function (event, ui) {
			var curr_cat_id = <?php echo $cat_id; ?>;
			if (curr_cat_id != $(this).attr('cat_id')) {
				var url = '<?php echo BASE_URL; ?>file/move/' + ui.draggable.attr('file_id');
				url += '/' + curr_cat_id + '/' + $(this).attr('cat_id');
				$.get(url, function (data) {
					if (!parseInt(data)) {
						location.reload();
					} else {
						alert('Error moving file');
					}
				}, 'text');
			}
		}
	});
});
</script>

<table border="0" bordercolor="red" width="100%" height="100%" cellspacing="0" cellpadding="0">
	<tr>
		<td style="width:250px; padding-<?php echo Config::get('align_not', 'i18n')?>:10px;">
			<?php
			foreach ($cat_list as $category) {
				$class_name = 'simple_tree_off';
				if ($cat_id == intval($category['id'])) {
					$class_name = 'simple_tree_on';
				} ?>
				
				<a href="<?php echo CURRENT_URL, $category['id']; ?>" class="<?php echo $class_name; ?>" style="margin-<?php echo Config::get('align', 'i18n')?>:<?php echo ($category['level'] * 5); ?>px;">
					<div class="simple_tree_item_off" cat_id="<?php echo $category['id']; ?>">
						<?php echo $category['name']; ?>
					</div>
				</a>
			<?php } ?>
		</td>
		<td style="padding:0px 0px 0px 5px;">
		<?php if (count($file_list) > 0) {
			$max_length = 100;
			foreach ($file_list as $file) {
				$style = '';
				if (in_array($file['extension'], Config::get('file_images_extensions'))) {
					if (!is_null($file['name_thumb'])) {
						$preview = UPLOAD_URL . $file['name_thumb'];
					} else {
						$preview = UPLOAD_URL . $file['name'];
					}

					if ((intval($file['width']) > $max_length) || (intval($file['height']) > $max_length)) {
						if (intval($file['width']) >= intval($file['height'])) {
							$style .= 'width:' . $max_length . 'px;';
						} else {
							$style .= 'height:' . $max_length . 'px;';
						}
					}
				} else {
					$file_icon = File::getIcon($file['extension']);
					$preview = PUBLIC_URL . 'images/file/' . $file_icon;
					$style = 'width:48px; height:48px;';
				}
				$popup = $file['name_orig']; ?>
				<div style="padding:0px 5px 5px 0px; float:<?php echo Config::get('align', 'i18n')?>;">
					<div title="<?php echo $popup; ?>" class="files_item" file_id="<?php echo $file['id']; ?>" style="width:112px; height:140px; border:1px solid #ccc; background:#eee; padding:5px; cursor:pointer;" onclick="Core.Tools.redirect('<?php echo BASE_URL; ?>file/update/<?php echo $file['id']; ?>')">
						<div style="width:110px; height:110px; display:table-cell; vertical-align:middle; border:1px solid #ccc; background:#fff;"><img src="<?php echo $preview; ?>" style="display:block; margin:auto; <?php echo $style; ?>" alt="File" /></div>
						<div style="font-size:0.8em; padding-top:5px;">
							<div><b>Size:</b> <?php echo File::formatSize($file['size']); ?></div>
							<?php if ((intval($file['width']) > 0) && (intval($file['height']) > 0)) {?>
								<div><b>Dim:</b> <?php echo $file['width'], ' x ', $file['height']; ?></div>
							<?php } ?>
						</div>
					</div>
				</div>
			<?php }
		} else { ?>
			No files found
		<?php } ?>
		</td>
	</tr>
</table>